package com.atguigu.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ Author:任留辉
 * @ Description:
 * @ Date:Created in 9:26 2021/3/17 0017
 */
public class CreateCookieServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            //创建cookie
        Cookie cookie = new Cookie("username", "Tom");
        Cookie cookie1 = new Cookie("name", "sun");
        Cookie cookie2 = new Cookie("user", "Moon");
        //cookie.setMaxAge(7200);
        cookie.setPath(request.getContextPath()+"/index.html");
        //将Cookie对象放入response对象中,发送到浏览器
        response.addCookie(cookie);
        response.addCookie(cookie1);
        response.addCookie(cookie2);




    }
}
